package com.example.administrator.exkotlin.net

import android.util.Log
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

/**
 * Author by lp,on 2020/8/27/027,11:27.
 */
class RetrofitIml : IHttpRqust {
    override fun <T> excute(istener: IHttpRqust.URlListener?, request: T) {
        //创建对应请求的service
        val service = RetrofitCreator.create(SpeedService::class.java)
        //制定具体请求以及参数
        val speedCall = service.getSpeedInfo("yuantong", "11111111111")
        //开启异步请求
        speedCall.enqueue(object : Callback<ResponseData> {
            override fun onFailure(call: Call<ResponseData>, t: Throwable) {
                istener?.response("请求失败${t.message}")
            }

            override fun onResponse(call: Call<ResponseData>, response: Response<ResponseData>) {
                //直接获取response的body已经转换为对应的类
                val responseData = response.body() as ResponseData
                Log.i("RetrofitIml", responseData.toString())
                istener?.response(responseData.toString())
            }

        })
    }


}